home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / compression / lister12.lha / Output.c < prev    next >
Encoding:
Text File  |  1992-04-02  |  2.0 KB  |  80 lines

  1. /* Prints an error message */
  2. void
  3. Error(char *str)
  4. {
  5.   printf("\nError : %s\n\n",str);
  6.   exit(0);
  7. }
  8.  
  9. /* checks to see if an error condition exists */
  10. void CheckError(int num)
  11. {
  12.   switch (num)
  13.    {
  14.      case TRUE          : return;
  15.      case FILE_ERROR    : Error("File Error - aborting listing.\n");
  16.      case NOTFOUND      : Error("Archive file not found.");
  17.      case WRONG_ARCHIVE : Error("Archive header is invalid.");
  18.      case UNKNOWN       : Error("Unknown archive type.");
  19.    }
  20. }
  21.  
  22. /*  print header for listing archives and reset stat values */
  23. void
  24. InitList(ULONG type,UBYTE *infile)
  25. {
  26.   printf("\n");
  27.   switch (type) {
  28.     case ARC    : printf("Arc");   break;
  29.     case ARJ    : printf("Arj");   break;
  30.     case CPIO   : printf("Cpio");  break;
  31.     case LHA    : printf("LHA");   break;
  32.     case LHARC  : printf("Lharc"); break;
  33.     case SIT    : printf("Sit");   break;
  34.     case TAR    : printf("Tar");   break;
  35.     case ZIP    : printf("Zip");   break;
  36.     case ZOO    : printf("Zoo");   break;
  37.     }
  38.   printf(" Archive: %s\n\n",infile);
  39.   dashes();
  40.   printf("  Original  Compress  Ratio       Date      Time    Filename\n");
  41.   dashes();
  42. }
  43.  
  44. /*  print entry in archive listing and update stats */
  45. void
  46. PrintList(char *n, ULONG u, ULONG c,ULONG *tfiles,ULONG *tcomp,ULONG *tuncomp,UBYTE *time_str)
  47. {
  48.   ULONG f;
  49.  
  50.   if ( (c==0) || (u==0) ) f = 0;
  51.    else f = (c * 1000) / u;
  52.   (*tfiles)++;  (*tcomp) += c;
  53.   (*tuncomp) += u;
  54.   printf("  %-10ld%-10ld%3ld.%ld%%  %-22s%s\n", u, c, f/10,f%10, time_str, n);
  55. }
  56.  
  57. /* prints the total statistics on the archive */
  58. void
  59. EndStats(ULONG tfiles,ULONG tcomp,ULONG tuncomp)
  60. {
  61.   ULONG cf;
  62.   char temp[6];
  63.  
  64.   if (tfiles == 1) strcpy(temp, "file");
  65.    else strcpy(temp, "files");
  66.   if (tuncomp == 0) cf = 0;
  67.    else cf = (tcomp * 1000) / tuncomp;
  68.   dashes();
  69.   printf("  %-10ld%-10ld%3ld.%ld%%        %d %s processed.\n\n", tuncomp, tcomp,cf/10, cf%10, tfiles, temp);
  70. }
  71.  
  72. void dashes(void)
  73. {
  74.   int i;
  75.   char dash[80];
  76.   for (i=0; i < 75; i++)
  77.    dash[i] = '-';
  78.   dash[i] = 0;
  79.   printf("%s\n",dash);
  80. }